<?php

namespace App\Command\ResumeParsing\Service\ParsingSpecial;

use EchoPHP\Facades\Log;

class ParsingMachineLearning extends ParsingSpecial {

    /**
     * @var array
     */
    private $data;
    /**
     * @var string
     */
    private $txt;
    /**
     * @var string
     */
    private $machineLearningUrl;
    /**
     * @var string
     */
    private $resumeText;
    /**
     * @var bool 前端请求直接调起的解析过程，而非来自后台队列
     */
    private $urgent;
    /**
     * @var string
     */
    //private $jsonDumpPath;
    private $autoFix;


    public function __construct($helper) {
        parent::__construct($helper);
        $this->autoFix = config('app.resume_machine_learning.fix_machinelearning_result');
        if (config('app.resume_machine_learning.mode', 0)) {
            $this->machineLearningUrl = config('app.resume_machine_learning.url');
            //$this->jsonDumpPath = config('app.resume_machine_learning.json_dump_path') . '/';
        }

        $this->get['id'] = $this->tagNotExist;

        $this->get['time'] = function () {
            return $this->data['baseinfo']['updatetime'] ?? '';
        };

        $this->get['name'] = function () {
            if (!empty($this->data['baseinfo']['cname'])) {
                return $this->data['baseinfo']['cname'];
            }
            if (!empty($this->data['baseinfo']['alias'])) {
                return $this->data['baseinfo']['alias'];
            }
            return '';
        };

        $this->get['sex'] = function () {
            return $this->data['baseinfo']['sex'] ?? '';
        };

        $this->get['nation'] = function () {
            return $this->data['baseinfo']['ethnic'] ?? '';
        };

        $this->get['identitycard'] = function () {
            return $this->data['baseinfo']['idcard'] ?? '';
        };

        $this->get['mobile'] = function () {
            $mobile = '';
            if (isset($this->data['contact_info']) && isset($this->data['contact_info']['mobilephone'])) {
                $mobile = $this->data['contact_info']['mobilephone'];
                //剔除手机号中的中英文
                $mobile = preg_replace('/[^0-9\+\-]+/', '', $mobile);
            }
            if ((strlen($mobile) < 8 || strlen($mobile) > 15) && $this->autoFix) {
                if (preg_match('/1[345678]\d{9}|1[345678]\d[\-—]\d{4}[\-—]\d{4}/', $this->resumeText, $match)) {
                    $mobile = isset($match[0]) ? preg_replace('/[\-—]/','',$match[0]) : '';
                }
            }
            return $mobile;
        };

        $this->get['email'] = function () {
            return $this->data['contact_info']['email'] ?? '';
        };

        $this->get['age'] = function () {
            return $this->data['baseinfo']['age'] ?? '';
        };

        $this->get['married'] = function () {
            return $this->data['baseinfo']['marriage'] ?? '';
        };

        $this->get['politic'] = function () {
            return $this->data['baseinfo']['politics_status'] ?? '';
        };

        $this->get['degree'] = function () {
            return $this->data['baseinfo']['topdegree'] ?? '';
        };

        $this->get['industry'] = function () {
            return $this->data['baseinfo']['expectindustry'] ?? '';
        };

        $this->get['position'] = function () {
            if (in_array($this->data['baseinfo']['cexpectposition'],['无','未填写'])) {
                return '';
            }
            return isset($this->data['baseinfo']['cexpectposition']) ? str_replace("\n",' ',$this->data['baseinfo']['cexpectposition']) : '';
        };

        $this->get['career'] = $this->tagNotExist;

        $this->get['major'] = function () {
            return $this->data['baseinfo']['topmajor'] ?? '';
        };

        $this->get['birthday'] = function () {
            return $this->data['baseinfo']['birthday'] ?? '';
        };

        $this->get['workyear'] = function () {
            return $this->data['baseinfo']['num_work_experience'] ?? '';
        };

        $this->get['workarea'] = function () {
            return $this->data['baseinfo']['area'] ?? '';
        };

        $this->get['expectarea'] = function () {
            return $this->data['baseinfo']['expectarea'] ?? '';
        };

        $this->get['area'] = function () {
            return $this->data['baseinfo']['hukou'] ?? '';
        };

        $this->get['salary'] = function () {
            $resultText = $this->data['baseinfo']['inputsalary'] ?? '';
            $salary = $this->func->parseSalary($resultText);
            if (count($salary)) {
                $this->helper->resumeInfo['salaryfrom'] = $salary['monthly']['begin'];
                $this->helper->resumeInfo['salaryend'] = $salary['monthly']['end'];
            }
            return $resultText;
        };

        $this->get['expectsalary'] = function () {
            $resultText = strtolower($this->data['baseinfo']['expectsalary'] ?? '');
            $expectSalary = $this->func->parseSalary($resultText);
            if (count($expectSalary)) {
                $this->helper->resumeInfo['expectsalaryfrom'] = $expectSalary['monthly']['begin'];
                $this->helper->resumeInfo['expectsalaryend'] = $expectSalary['monthly']['end'];
            }
            return $resultText;
        };

        $this->get['jobterm'] = function () {
            if (empty($this->data['baseinfo']['isfulltime'])) return '';
            if ($this->data['baseinfo']['isfulltime'] == '是') return '全职';
            if ($this->data['baseinfo']['isfulltime'] == '否') return '兼职';
            return $this->data['baseinfo']['isfulltime'];
        };

        $this->get['entrytime'] = function () {
            return $this->data['baseinfo']['entrytime'] ?? '';
        };

        $this->get['current_situation'] = function () {
            return $this->data['baseinfo']['current_situation'] ?? '';
        };

        $this->get['school'] = function () {
            return $this->data['baseinfo']['school_name'] ?? '';
        };

        $this->get['nofocuse'] = function () {
            return $this->data['baseinfo']['company_not_recommend'] ?? '';
        };

        $this->get['workinfo'] = function () {
            $data = [];
            if (empty($this->data['work']) || !is_array($this->data['work'])) return $data;
            foreach ($this->data['work'] as $item) {
                $data[] = [
                    'time_from' => $this->func->parseTimespan($item['timefrom'] ?? '')['begin'],
                    'time_end' => $this->func->parseTimespan($item['timeto'] ?? '')['begin'],
                    'company' => $item['ccompname'] ?? '',
                    'industry' => $item['workindustry'] ?? '',
                    'duty' => isset($item['cposition']) ? str_replace("\n",' ',$item['cposition']) : '',
                    'salary' => $item['salary'] ?? '',
                    'comment' => $item['cworkdescribe'] ?? '',
                ];
            }
            return $data;
        };

        $this->get['projectinfo'] = function () {
            $data = [];
            if (empty($this->data['project']) || !is_array($this->data['project'])) return $data;
            foreach ($this->data['project'] as $item) {
                $data[] = [
                    'time_from' => $this->func->parseTimespan($item['timefrom'] ?? '')['begin'],
                    'time_end' => $this->func->parseTimespan($item['timeto'] ?? '')['begin'],
                    'project' => $item['cprojectname'] ?? '',
                    'company' => $item['ccompname'] ?? '',
                    'duty' => $item['cfunction'] ?? '',
                    'comment' => $item['cdescribe'] ?? '',
                ];
            }
            return $data;
        };

        $this->get['educationinfo'] = function () {
            $data = [];
            if (empty($this->data['education']) || !is_array($this->data['education'])) return $data;
            foreach ($this->data['education'] as $item) {
                $data[] = [
                    'time_from' => $this->func->parseTimespan($item['timefrom'] ?? '', true)['begin'],
                    'time_end' => $this->func->parseTimespan($item['timeto'] ?? '', true)['begin'],
                    'school' => $item['cschoolname'] ?? '',
                    'major' => $item['major'] ?? '',
                    'degree' => $item['degree'] ?? '',
                    'comment' => !empty($item['GPA']) ? 'GPA：' . $item['GPA'] : '',
                ];
            }
            return $data;
        };

        $this->get['skillinfo'] = function () {
            $resultText = $this->data['others']['skills'] ?? '';
            if (!empty($this->data['others']['itskill'])) $resultText .= "\r\n" . $this->data['others']['itskill'];
            if (!empty($this->data['others']['language'])) $resultText .= "\r\n语言：" . $this->data['others']['language'];
            return trim($resultText);
        };

        $this->get['awardinfo'] = function () {
            return $this->data['others']['schoolaward'] ?? '';
        };

        $this->get['commentinfo'] = function () {
            return $this->data['others']['cselfintro'] ?? '';
        };

        $this->get['otherinfo'] = function () {
            $this->helper->resumeInfo['jsonData'] = $this->data;
            $this->helper->resumeInfo['data'] = $this->txt;
            //body/p[ppr/pbdr/bottom[@*[local-name()='w:color' and .='E7E7E7']]]
            if (!empty($this->helper->resume['resumeDom'])) {
                $rInfo = &$this->helper->resumeInfo;
                $xPath = new \DOMXPath($this->helper->resume['resumeDom']);
                //$idNode = $xPath->query("//body/p[ppr/pbdr/bottom[@*[local-name()='w:color' and .='E7E7E7']] and starts-with(normalize-space(),'个人信息')]/following-sibling::*[self::tbl//drawing]//pic[1]/blipfill/blip/@*[local-name()='r:embed']");
                //  /html/body/document/body/tbl[1]/tr[2]/tc[1]/p/r[2]/drawing/inline/graphic/graphicdata/pic/blipfill/blip/@r:embed
                //$idNode = $xPath->query("//text()[contains(., '个人信息')]");
                //$idNode = $xPath->query("//pic");
                //$idNode = $xPath->query("//rId7");
                //$idNode = $xPath->query("//blipfill[contains(., 'blip')]");
                //$idNode = $xPath->query("//blipfill/blip/@*[local-name()='r:embed']");
                //$idNode = $xPath->query("//body/p[starts-with(normalize-space(),'个人信息')]/following-sibling::*[self//drawing]//pic/blipfill/blip/@*[local-name()='r:embed']");
                $idNode = $xPath->query("//drawing//pic/blipfill/blip/@*[local-name()='r:embed']");

                if (count($idNode)) {
                    //https://www.php.net/manual/en/class.domnode.php
                    foreach ($idNode as $key => $item) {
                        //var_dump($item->getNodePath());
                        //var_dump($item->nodeValue);
                        //echo '<br/><br/>';
                        //var_dump($item->textContent);
                        $strPic = $this->helper->resume['resumeImage'][$item->textContent];
                        if (!empty($strPic)) {

                            $res = $this->func->getInfoFromImg(base64_encode($strPic['data']));
                            if ($res['result'] == 1 && (!empty($res['message']['name']
                                    || !empty($res['message']['phone']) || !empty($res['message']['email'])
                                    || !empty($res['message']['year'])))) {
                                $info = $res['message'];
                                if (isset($info['name']) || isset($info['phone']) || isset($info['email'])) {
                                    if (isset($info['name']) && !empty($info['name'])) {
                                        $rInfo['name'] = $info['name'];
                                    }
                                    if (isset($info['phone']) && !empty($info['phone'])) {
                                        $rInfo['mobile'] = $info['phone'];
                                    }
                                    if (isset($info['email']) && !empty($info['email'])) {
                                        $rInfo['email'] = $info['email'];
                                    }
                                    if (isset($info['year']) && !empty($info['year'])) {
                                        $rInfo['workyear'] = $info['year'];
                                    }
                                    break;
                                }
                            } else if ($res['result'] == -99999) {
                                Log::error('调用OCR服务失败', ['result' => $res], 'cmd');
                            }
                        }
                    }
                }
            }
            $resultText = '';
            $map = [
                '证书' => $this->data['others']['certification'] ?? '',
                '校内职务' => $this->data['others']['schooljob'] ?? '',
                '其他' => $this->data['others']['others'] ?? ''
            ];
            foreach ($map as $key => $value) {
                if (!empty($value)) $resultText .= "\r\n" . $key . "\r\n" . $value;
            }
            return trim($resultText);
        };
    }

    //自定义初始化数据逻辑，可以被重载
    protected function onParseInit(...$params) {
        if (count($params) < 1) throw new \ArgumentCountError('array $resume expected, none given');
        if (!is_array($params[0])) throw new \InvalidArgumentException('array $resume expected');
        $this->resumeText = $params[0]['resumeText'] ?? '';
        $this->urgent = !empty($params[0]['urgent']);
    }

    protected function test() {
        if (empty($this->machineLearningUrl)) return false;
        if (empty(trim($this->resumeText))) {
            if (empty($this->helper->resume) || empty($this->helper->resume['resumeAtom'])) {
                return false;
            }
            $this->resumeText = $this->helper->func->replaceChar16($this->helper->func->aloneChar16($this->helper->resume['resumeAtom']));
        }


        $tmp = $this->getMachineLearningResult($this->resumeText);
        $tmpTime = 0;
        if (!$tmp) {
            if ($this->urgent) {
                return false;
            }    //前端调起的解析不能被阻塞
            do {
                sleep(10);
                $tmp = $this->getMachineLearningResult($this->resumeText, true);
                //设置重试次数上限，否则在机器学习内容无法获取时，将无限次调用该循环
                if (!$tmp) {
                    $tmpTime++;
                }
                if ($tmpTime > 3) {
                    file_put_contents(ROOT_PATH.'/app/Command/ResumeParsing/machinelearning_status.txt','error');
                    return false;
                }
            } while (!$tmp);
        }
        $this->data = $tmp;
        return true;
    }

    protected function onParsed() {
        //var_dump($this->data);  exit();
    }

    private function getMachineLearningResult($data, $logOnError = true) {
        $data = trim($data);
        $data = $this->charsetToGBK($data);
        $data = $this->charsetToUTF8($data);
        $data = $this->formatText($data);

        //return json_decode('{"data": {"project": [{"cdescribe": "\u4ea4\u901a\u94f6\u884ce\u6821\u56ed\u793e\u533a\u5e73\u53f0\u6240\u5c5e\u516c\u53f8:\u4e0a\u6d77\u6cd3\u667a\u4fe1\u606f\u79d1\u6280\u6709\u9650\u516c\u53f8\u9879\u76ee\u63cf\u8ff0:e\u6821\u56ed\u662f\u6574\u4e2a\u4ea4\u884c\u5185\u90e8\u4eba\u5458\u5b66\u4e60\u548c\u4ea4\u6d41\u7684\u4e00\u4e2a\u5e73\u53f0\uff0c\u91cc\u9762\u6709\u4e30\u5bcc\u7684\u8d44\u6e90\u53ef\u4ee5\u5b66\u4e60\uff0c\u6bd4\u5982\u8bfe\u4ef6\u3001\u89c6\u9891\u3001\u95ee\u7b54\u3001\u535a\u5ba2\u3001\u6587\u6863\u3001\u6848\u4f8b\u3001\u5e16\u5b50\u7b49\u7b49\u8d44\u6e90\u30022013/9-2014/4\u9910\u996e\u732b\u6240\u5c5e\u516c\u53f8:\u4e0a\u6d77\u7c73\u6597\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8\u9879\u76ee\u63cf\u8ff0:\u8be5\u9879\u76ee\u4e3b\u8981\u9488\u5bf9\u9910\u996e\u52a0\u76df\uff0c\u7279\u8272\u996e\u54c1\u54c1\u724c\u7684\u8425\u9500\u63a8\u5e7f\u7684\u9879\u76ee\uff0c\u9879\u76ee\u524d\u53f0\u4e3b\u8981\u5728\u4e8e\u5c55\u793a\uff0c\u548c\u987e\u5ba2\u7559\u8a00\u3002\u540e\u53f0\u4e3b\u8981\u662f\u4e00\u4e9b\u4fe1\u606f\u7684\u4e0a\u4f20\uff0c\u4fee\u6539\uff0c\u5220\u9664\u3002\u4e3b\u8981\u4f7f\u7528\u7684\u6280\u672f\u662fwamp\uff0cphpcms\u4e8c\u6b21\u5f00\u53d1\u6846\u67b6\uff0cdivcssjavascriptjQuery\u8d23\u4efb\u63cf\u8ff0:\u672c\u4eba\u5728\u91cc\u9762\u4e3b\u8981\u8d1f\u8d23\u7684\u662f\u9875\u9762\u5236\u4f5c\uff0c\u540e\u53f0\u529f\u80fd\u7ba1\u7406\u5f00\u53d1\uff0c\u6570\u636e\u5e93\u8bbe\u8ba1\uff0c\u524d\u53f0\u9875\u9762\u6570\u636e\u5957\u7528\u3002", "cprojectname": ":", "timefrom": "4", "location": null, "cfunction": "2016.11", "timeto": "\u81f3\u4eca", "ccompname": ":\u56db\u5ddd\u5c71\u9f0e\u5efa\u7b51\u5de5\u7a0b\u8bbe\u8ba1\u80a1\u4efd\u6709\u9650\u516c\u53f8"}], "baseinfo": {"cexpectposition": "\u5b66\u4f4d\u4e13\u4e1a:\u4fe1\u606f\u5b89\u5168\u5b66\u6821:\u4e2d\u56fd\u5730\u8d28\u5927\u5b66\uff08\u6b66\u6c49\u5e76\u4e14\u72ec\u7acb\u4e0a\u673a\u5230\u670d\u52a1\u5668\u64cd\u4f5c2013/9", "num_work_experience": "\"\\\n\"16.0\u5e74\u5de5\u4f5c\u7ecf\u9a8c", "company_not_recommend": "2014/4\u4e0a\u6d77\u7c73\u6597\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8(7", "detailed_location": null, "sex": "\u7537", "marriage": "\u5df2\u5a5a", "expectsalary": "10001.0-15000.0\u5143/\u6708", "topmajor": null, "hukou": "\u6cb3\u5357\u5468\u53e3", "isfulltime": null, "ethnic": null, "cname": "@qq.com", "expectindustry": ":\u5feb\u901f\u6d88\u8d39\u54c1\uff08\u98df\u54c1/\u996e\u6599/\u70df\u9152/\u65e5\u5316\uff09,\u6c7d\u8f66/\u6469\u6258\u8f66,\u5927\u578b\u8bbe\u5907/\u673a\u7535\u8bbe\u5907/\u91cd\u5de5\u4e1a\"\\\n\"", "topdegree": "18620489520", "birthday": "1980.0\u5e745.0\u6708", "zipcode": null, "inputsalary": "24\u4e07\uff0820000\u5143/\u6708*12\u4e2a\u6708\uff09", "school_type": null, "expectarea": "\"\u5de5\u4f5c\u5730\u70b9:\u5e7f\u4e1c-\u5e7f\u5dde", "idcard": null, "politics_status": null, "age": "39.0\u5c81", "school_name": null, "area": ":\u5e7f\u4e1c\u5e7f\u5dde", "topposition": ":\u5efa\u7b51\u8bbe\u8ba1\u5e08", "current_situation": "\u79bb\u804c", "current_company": ":\u6052\u5927\u5730\u4ea7\u96c6\u56e2\u6709\u9650\u516c\u53f8", "topindustry": ":5\u5e74\u4ee5\u4e0a", "updatetime": "2019-06-2510:21:53", "workyear": null}, "others": {"schooljob": null, "business_skills": null, "others": null, "schoolaward": "\u65b0\u589e\u7684\u8ba1\u5212\u4efb\u52a1\u6bcf\u6b21\u6295\u4ea7\u524d\u90fd\u4f1a\u51c6\u5907\u597d\uff0c", "certification": "\u5de5\u4f5c\uff082\u5e7411\u4e2a\u6708\uff09\u804c\u4f4d:PHP", "cselfintro": "\u5de5\u4f5c\uff082\u5e7411\u4e2a\u6708\uff09\u804c\u4f4d:PHP\u548c\u4eba\u5458\u5206\u914d\uff0c\u79ef\u7d2f\u4e86\u4e30\u5bcc\u7684\u7ecf\u9a8c\u30022.\u5bf9\u4e8e\u6570\u636e\u5e93\u65b9\u9762\uff0c\u9879\u76ee\u7684\u6570\u636e\u5e93\u8bbe\u8ba1\u3001\u5f00\u53d1\u548c\u4f18\u5316\u5747", "itskill": null, "language": ":\u82f1\u8bed\u3001\u666e\u901a\u8bdd", "skills": "\u66f4\u65b0\u65f6\u95f4:2017-03-13\u65b9\u661f\u6d41\u7a0b\u72b6\u6001:\u6807\u7b7e:ID:9613714744\u5e74"}, "education": [{"cschoolname": "2009/9", "study_model": null, "school_level": null, "school_rank": null, "major": "\u4fe1\u606f\u5b89\u5168", "degree": "\u672c\u79d1", "location": null, "department": null, "isfulltime": "\u662f", "timefrom": "\u5e74", "GPA": null, "courses": null, "timeto": "2003.0\u5e747.0\u6708", "ranking": null}], "work": [{"creportboss": "\u90e8\u95e8\u603b\u7ecf\u7406", "cposition": "\u6280\u672f\u90e8PHP\u5f00\u53d1\u5de5\u7a0b\u5e08", "reportperson": null, "ccompname": "\u4e0a\u6d77\u6cd3\u667a\u4fe1\u606f\u79d1\u6280\u6709\u9650\u516c\u53f8", "workindustry": "\u4e92\u8054\u7f51/\u7535\u5b50\u5546\u52a1", "cworkdescribe": "4", "cdepartment": "\u521b\u4e1a\u516c\u53f8", "salary": "\u5c45\u4f4f", "company_description": "\u8fd9\u5bb6\u516c\u53f8\u4e1a\u52a1\u4e00\u76f4\u662f\u7ed9\u5404\u4e2a\u94f6\u884c\u63d0\u4f9b\u670d\u52a1\u3002\u6211\u4eec\u9879\u76ee\u7ec4\u88ab\u6d3e\u5f80\u4ea4\u901a\u94f6\u884c\uff0c", "workfunc": null, "timefrom": "\u81f3\u4eca", "location": "\u9ad8\u7ea7\u5f00\u53d1\u5de5\u7a0b\u5e08", "company_type": "\u5916\u5546\u72ec\u8d44", "timeto": "\u4e0a\u6d77", "companysize": "500-1000\u4eba"}]}, "error": "", "code": "1"}', true);
        $ch = curl_init($this->machineLearningUrl);
        # Setup request to send json via POST.
        curl_setopt($ch, CURLOPT_TIMEOUT, 60);   //单位 秒，也可以使用
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(array("upload_text" => array($data))));
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
        # Return response instead of printing.
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $result = curl_exec($ch);
        curl_close($ch);
        $tmp = json_decode($result, true);
        $this->txt = $data;
        if (empty($tmp) || empty($tmp['code']) || $tmp['code'] != 1) {
            if ($logOnError) {
//                $time = explode(' ', microtime());
//                file_put_contents($this->jsonDumpPath . 'raw/' . $this->helper->resume['taskid'] . ' [' . date('Y-m-d_H-i-s', $time[1]) . '.' . $time[0] . '].json', $result);
                Log::error('fail to get machine learning parsing result', ['response' => $result], 'cmd');
            }
            return false;
        }
        //机器学习获取测试txt用
        if (1 == 0) {
            $time = explode(' ', microtime());
            $txtPath = config('app.resume_machine_learning.parse_txt_path') . '/' . $this->helper->resume['taskid'] . ' [' . date('Y-m-d_H-i-s', $time[1]) . '.' . $time[0] . ']';
            file_put_contents($txtPath . '.txt', $data);
        }

        return $tmp['data'];
    }

    function charsetToGBK($mixed) {
        $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
        if ($encode == 'UTF-8') {
            $mixed = iconv('UTF-8', 'GBK//IGNORE', $mixed);
        }
        return $mixed;
    }

    /**
     * 将非UTF-8字符集的编码转为UTF-8
     *
     * @param mixed $mixed 源数据
     *
     * @return mixed utf-8格式数据
     */
    function charsetToUTF8($mixed) {
//        $encode = mb_detect_encoding($mixed, array('ASCII', 'UTF-8', 'GB2312', 'GBK', 'BIG5'));
        $mixed = iconv('GBK', 'UTF-8//IGNORE', $mixed);

        return $mixed;
    }

    function formatText($resumeText) {
        $resumeText = preg_replace('/\s{2,}\|\s{2,}/', ' ', $resumeText);
        $resumeText = preg_replace('/ {2,}/', ' ', $resumeText); //连续多个空格保留一个
        $resumeText = preg_replace('/\[pic\]/', '', $resumeText);
        $resumeText = preg_replace('/p[\r\n]*?i[\r\n]*?c/', ' ', $resumeText);
        $resumeText = preg_replace('/[\|\[\|]|[\|\]\|]|[\|\]]|[\[\|]/', '|', $resumeText);
        $resumeText = preg_replace('/\|\s*?\|/', ' ', $resumeText);
        $resumeText = preg_replace('/\|{2,}/', '|', $resumeText);
        $resumeText = preg_replace('/\s{2,}/', "\n", $resumeText);
        $resumeText = preg_replace('/left00|right00|left|right/', '', $resumeText);
        $resumeText = preg_replace('/HYPERLINK/', '', $resumeText);
        return $resumeText;
    }
}
